﻿namespace NEvoWeb.Modules.NB_Store
{
    using DotNetNuke.Common;
    using DotNetNuke.Entities.Modules;
    using DotNetNuke.Entities.Portals;
    using DotNetNuke.Services.Localization;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections;
    using System.Runtime.CompilerServices;
    using System.Xml;

    public class BasePortController : IPortable
    {
        public virtual string ExportModule(int ModuleID)
        {
            string str2 = "";
            LocaleCollection supportedLocales = DotNetNuke.Services.Localization.Localization.GetSupportedLocales();
            Hashtable moduleSettings = PortalSettings.GetModuleSettings(ModuleID);
            str2 = str2 + "<modulecontent>" + "<settings>";
            IDictionaryEnumerator enumerator = moduleSettings.GetEnumerator();
            while (enumerator.MoveNext())
            {
                DictionaryEntry current = (DictionaryEntry) enumerator.Current;
                if (!Versioned.IsNumeric(RuntimeHelpers.GetObjectValue(current.Key)))
                {
                    str2 = str2 + "<" + current.Key.ToString() + "><![CDATA[" + current.Value.ToString() + "]]></" + current.Key.ToString() + ">";
                }
            }
            return (str2 + "</settings>" + "</modulecontent>");
        }

        public virtual void ImportModule(int ModuleID, string Content, string Version, int UserId)
        {
            IEnumerator enumerator2=null;
            XmlNode content = Globals.GetContent(Content, "modulecontent");
            ModuleController controller = new ModuleController();
            IDictionaryEnumerator enumerator = PortalSettings.GetModuleSettings(ModuleID).GetEnumerator();
            while (enumerator.MoveNext())
            {
                DictionaryEntry current = (DictionaryEntry) enumerator.Current;
                controller.DeleteModuleSetting(ModuleID, current.Key.ToString());
            }
            XmlNode node2 = content.SelectSingleNode("settings");
            try
            {
                enumerator2 = node2.SelectNodes("*").GetEnumerator();
                while (enumerator2.MoveNext())
                {
                    XmlNode node = (XmlNode) enumerator2.Current;
                    controller.UpdateModuleSetting(ModuleID, node.Name, node2.SelectSingleNode(node.Name).InnerText);
                }
            }
            finally
            {
                if (enumerator2 is IDisposable)
                {
                    (enumerator2 as IDisposable).Dispose();
                }
            }
        }
    }
}

